//
//  ShufflingFigureView.m
//  news
//
//  Created by lanou on 15/12/17.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "ShufflingFigureView.h"
#import "ShufflingFigure.h"

@implementation ShufflingFigureView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target action:(SEL)action shufflingFigureArray:(NSArray *)shufflingFigureArray
{
    if (self = [super initWithFrame:frame]) {
        NSMutableArray *insterImageArray = [NSMutableArray arrayWithArray:shufflingFigureArray];
        [insterImageArray insertObject:shufflingFigureArray.lastObject atIndex:0];
        self.contentSize = CGSizeMake(insterImageArray.count * kWidth, 0);
        self.bounces = YES;
        self.delegate = target;
        self.pagingEnabled = YES;
        self.showsHorizontalScrollIndicator = NO;
        self.contentOffset = CGPointMake(kWidth, 0);
        for (int i = 0; i < insterImageArray.count; i ++) {
            ShufflingFigure *shufflingFigure = insterImageArray[i];
            
            TapImageView *tapImageView = [[TapImageView alloc] initWithFrame:CGRectMake(i * kWidth, 0, kWidth, self.bounds.size.height - 30) target:target action:action];
            [tapImageView setImageWithURL:[NSURL URLWithString:shufflingFigure.imgsrc]];
            [self addSubview:tapImageView];
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(i * kWidth + 10, self.bounds.size.height - 25, kWidth - 20, 20)];
            label.text = shufflingFigure.title;
            label.font = [UIFont boldSystemFontOfSize:16.0];
            [self addSubview:label];
            
        }
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
